#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int n, m, cnt[N];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    cnt[(x + y) % n]++;//找出每种平行线的数量
  }
  
  //排除法，
  long long ans = m * 111 * (m - 1) / 2;
  for (int i = 0; i < n; ++i) {
    ans -= cnt[i] * 1ll * (cnt[i] - 1) / 2;
  }

  printf("%1ld\n", ans);
  return 0;
}
